package cn.yi.elasticjob.job;

import cn.yi.elasticjob.annotation.ElasticJobConf;
import com.dangdang.ddframe.job.api.ShardingContext;
import com.dangdang.ddframe.job.api.simple.SimpleJob;

import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * @author: yiz
 * @date: 2018/7/30 13:58
 **/
@ElasticJobConf(name = "MySimpleJob", cron = "0/10 * * * * ?",
        shardingItemParameters = "0=0,1=1,2=2", description = "简单任务",shardingTotalCount = 3,overwrite = true)
public class MySimpleJob1 implements SimpleJob {

    public void execute(ShardingContext context) {
        String shardParamter = context.getShardingParameter();
        System.out.println("分片参数：" + shardParamter);
        int value = Integer.parseInt(shardParamter);
        for (int i = 0; i < 1; i++) {
            if (i % 2 == value) {
                String time = new SimpleDateFormat("HH:mm:ss").format(new Date());
                System.out.println(time + ":开始执行简单任务1:" + i+"--shard="+value);
            }
        }
    }
}
